The present invention relates to the field of computer operating systems and general application software, and more particularly to methods and apparatus for controlling the communication of events between an operating system and its application programs.
Computer programs are, in essence, a series of instructions that direct the operation of a computer. In general, a program performs the functions either of an operating system, which controls the interaction of the various components of the computer relatively independent of the use to which the computer is being put, or of an application which is designed to accomplish a specific task or tasks (e.g., word processing, spreadsheet, etc.)
Many operating system programs and virtually all application programs provide for, and in fact require, user interaction with the program. The scheme used to facilitate the user's interaction with the computer is referred to as the user interface.
Popular common user interfaces employ windows, which are discrete regions of the screen in which elements are displayed, and user interaction with the computer program may occur via scroll bars for scrolling up or down within a window, menus for selecting commands, icons representing applications and documents, etc. In conjunction with a program's user interface, hardware devices are provided for interaction with the programs. Examples of such hardware devices include a keyboard, a mouse, a disk drive, a network interface card, etc. The Macintosh line of computers from Apple Computer Inc. of Cupertino, Calif., operate with such a user interface and with such hardware.
Many modern application programs operate by looping repeatedly through the program, periodically polling the operating system software for an indication that at least one "event" has occurred. Events generally represent user activity via one or more of the hardware devices, but can also represent actions generated independently by external hardware devices, as well as internal "messages" sent by a system or application program.
When the application learns (by polling the system) that an event has occurred, the application must determine whether the event is of a type in which it is "interested" (i.e., an event in response to which the application program desires to perform some action), and if so, what action needs to be taken in response to that event. Since the application will not do anything until an event is encountered, this type of application is referred to as "event driven."
Examples of user-generated events include: typing on a keyboard (also referred to as "key-down" and "key-up" events), depressing a button on a mouse (also referred to as "mouse-down" and "mouse-up" events), and inserting a disk in a disk drive. Events may also be generated indepedently by a hardware device (e.g., a signal from a network interface card indicating that a block of data has arrived over the network), as well as by an application or operating system program (e.g., a message indicating a particular state of the program, such as the completion of a spreadsheet calculation).
These events are typically handled, one at a time, by the application. In certain circumstances, applications are interested in a combination of events. For example, an application may desire to close a window if the user simultaneously depresses the "option" key and the mouse button (within that window). In this case, in deciding what action to take in response to the events generated by depressing these keys, the application program must determine if the key depressions occurred simultaneously.
In the Apple Macintosh, events are posted to an event queue, where they are metered out, one at a time, to the application by an Event Manager. Generally, events are retrieved by the application in a first-in-first-out order. However, some events may have a higher priority than other events, and in addition, an application may ask for certain events before others.
The precise manner by which events are generated, captured, and communicated to an application program varies from system to system, and is beyond the scope of this discussion. For a more detailed discussion of events and event handling, see INSIDE MACINTOSH, Apple Computer, Vol. 1, pp. 1-243 to 1-266, and other sections thereof (Addison-Wesley, 1985), incorporated herein by reference.
Event handling as presently practiced in the art presents a number of problems and disadvantages to which the present invention is addressed. One problem that arises in event handling, especially where combinations of events are involved, is that a significant amount of application program code is required to check for events, the order in which they occur, the proximity in time to other events, and the state of other system and application resources in which the application is interested. Likewise, the complexity of the application program code increases dramatically as the application is required to monitor for increasingly complex combinations of events and other conditions. The process of checking for the occurrence of these events and conditions requires not only a significant amount of application code, but also a significant amount of application processing time.
Another problem occurs when an application programmer seeks to provide a user with the ability to change the event or combination of events or other conditions which will trigger a certain action by the application program. For example, while an application may open a new window in response to the combination of certain key-down and mouse-down events which occur while the cursor is in a particular region of the screen, it may be desirable to provide the user with the ability to change the specific events or other conditions which trigger the opening of a new window--e.g., the single key-down event caused by depressing a dedicated "function" key. Allowing changes such as these generally requires either recompiling or "patching" the program, and only exacerbates the problems of code volume, complexity, and processing time. In general it is desirable to simplify the process of writing event driven applications, and as described below this forms the basis for the present invention.